4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
11 // You must not remove this notice, or any other, from this software.
15 // UTILB.C -- Data structure manipulation functions specific to OS/2
18 // This file was created from functions in util.c & esetdrv.c which were system
19 // dependent. This was done so that the build of the project became simpler and
20 // there was a clear flow in the build process.
22 // Method of Creation:
23 // 1. Identified all functions having mixed mode code.
24 // 2. Deleted all code blocked out by '#ifndef BOUND' preprocessor directives
26 // 3. Deleted all local function & their prototypes not referred by these
27 // 4. Deleted all global data unreferenced by these, including data blocked
28 // of by '#ifdef DEBUG'
38 char *s
// text to expand
41 struct _finddata_t finddata
;
42 NMHANDLE searchHandle
;
43 STRINGLIST
*xlist
, // list of expanded names
47 if (!(namestr
= findFirst(s
, &finddata
, &searchHandle
))) {
51 xlist
= makeNewStrListElement();
52 xlist
->text
= prependPath(s
, namestr
);
54 while ((namestr
= findNext(&finddata
, searchHandle
))) {
55 p
= makeNewStrListElement();
56 p
->text
= prependPath(s
, namestr
);
57 prependItem(&xlist
, p
);
64 // QueryFileInfo -- it does a DosFindFirst which circumvents FAPI restrictions
66 // Scope: Global (used by Build.c also)
69 // DosFindFirst() has a FAPI restriction in Real mode. You cannot ask it give
70 // you a handle to a DTA structure other than the default handle. This function
71 // calls C Library Function _dos_findfirst in real mode (which sets the DTA) and
72 // does the job. In protect mode it asks OS/2 for a new handle.
75 // file -- the file to be searched for
76 // dta -- the struct containing result of the search
78 // Output: Returns a pointer to the filename found (if any)
80 // Assumes: That dta points to a structure which has been allocated enough memory
83 // _osmode -- to determine whether in Real or Bound mode
94 // Remove Quotes around filename, if existing
95 t
= file
+ _tcslen(file
) - 1;
96 if (*file
== '"' && *t
== '"') {
97 file
= unQuote(file
); // file is quoted, so remove quote
101 if ((hDir
= _findfirst(file
, (struct _finddata_t
*) dta
)) == -1) {
107 return(((struct _finddata_t
*) dta
)->name
);
112 // Truncate filename to system limits
119 char szDrive
[_MAX_DRIVE
];
120 char szDir
[_MAX_DIR
];
121 char szName
[_MAX_FNAME
];
122 char szExtension
[_MAX_EXT
];
124 // pathname incorrectly truncated. Solution: first parse it
125 // using _splitpath(), then truncate the filename and extension part.
126 // Finally reconstruct the pathname by calling _makepath().
128 _splitpath(s
, szDrive
, szDir
, szName
, szExtension
);
129 _makepath(s
, szDrive
, szDir
, szName
, szExtension
);
135 char *s
, // text to expand
140 BOOL anyspecial
; // flag set if s contains special characters.
141 char buf
[_MAX_PATH
]; // buffer for removing ESCH
143 // Check if name contains any special characters
145 anyspecial
= (_tcspbrk(s
, "\"^*?") != NULL
);
149 char *x
; // Pointers for truncation, walking for ESCH
151 t
= s
+ _tcslen(s
) - 1;
153 // Copy pathname, skipping ESCHs and quotes
156 if (*s
== '^' || *s
== '"') {
160 if (_istlead(*(unsigned char *)s
))
167 s
= buf
; // only elide ESCH the first time!
172 if ((*dirHandle
= _findfirst(s
, (struct _finddata_t
*) dta
)) == -1) {
176 // If it had no wildcard then close the search handle
178 if (!anyspecial
|| (!_tcschr(s
, '*') && !_tcschr(s
, '?'))) {
179 _findclose(*dirHandle
);
182 return(((struct _finddata_t
*) dta
)->name
);
191 if (_findnext(dirHandle
, (struct _finddata_t
*) dta
)) {
192 _findclose(dirHandle
);
197 return(((struct _finddata_t
*) dta
)->name
);
204 // Convert $ to $$ before returning current dir
205 // This allows $(MAKEDIR) to work properly in
206 // case the current path contains a $ sign.
209 char pbPath
[_MAX_DIR
+1];
210 char *pchSrc
= pbPath
;
214 GetCurrentDirectoryA(_MAX_DIR
+1, pbPath
);
215 pszPath
= (char *) rallocate(2 * _tcslen(pbPath
) + 1);
219 // non-MBCS aware implementation ('$' can't be a trailbyte)
220 while ((ch
= *pchSrc
)) {
221 *pchDst
++ = *pchSrc
++;